package main

import "fmt"

func main() {
	nums := []int{3,2,4}
	target := 6

	fmt.Println(twoSum(nums, target))
}

func twoSum(nums []int, target int) []int {
	m := make(map[int][]int)
	for i := 0; i < len(nums); i++ {
		m[target-nums[i]] = append(m[target-nums[i]], i)
	}

	var rev []int
	for i := 0; i < len(nums); i++ {
		if v, ok := m[nums[i]];ok{
			if len(v) > 1 {
				return v
			} else {
				if v[0] != i {
					rev = append(rev, v[0])
				}
			}
		}
	}

	return rev
}
